#include <bits/stdc++.h>
using namespace std;

struct Node{
    long double in , sp , ad;
};

Node a[100011];
long double b[100011];
//long double sum[100011];
long double cnt1[100011];
long double cnt2[100011];

void solve(){
    memset(cnt1 , 0 , sizeof(cnt1));
    memset(cnt2 , 0 , sizeof(cnt2));
    int n , m , len , limit;
    cin >> n >> m >> len >> limit;
    for(int i = 1;i <= n;i++){
        cin >> a[i].in >> a[i].sp >> a[i].ad;
    }
    for(int i = 1;i <= m;i++){
        cin >> b[i];
    }
    int mx = -1;
    int mn = 1e9;
    int ans = 0;
    for(int i = 1;i <= n;i++){
        int mx1 = 1;
        int mn1 = m;
        long double x;
        if(a[i].ad != 0) x = a[i].in + (limit * limit - a[i].sp * a[i].sp) / (2 * a[i].ad);
        //cout << fixed << x << "\n";
        for(int j = 1;j <= m;j++){
            if(b[j] < a[i].in){
                continue;
            }
            if(a[i].ad == 0){
                if(a[i].sp > limit){
                    cnt1[i]++;
                    break;
                }
            }
            else if(a[i].ad > 0){
                if(b[j] > x){
                    cnt1[i]++;
                    mn1 = j;
                    break;
                }
            }
            else{
                if(a[i].sp < limit){
                    break;
                }
                if(b[j] < x){
                    cnt1[i]++;
                    mx1 = j;
                }
            }
        }
        if(cnt1[i]){
            //cout << i << " " << mx1 << " " << mn1 << "\n";
            ans++;
            if(a[i].ad > 0){
                //cout << mx1 << "\n";
                mx = max(mx , mn1);
            }
            else{
                //cout << mn1 << "\n";
                mn = min(mn , mx1);
            }
        }
    }
    if(mx == -1){
        cout << ans << " " << m - mn + 1 << "\n";
    }
    else if(mn == 1e9){
        cout << ans << " " << m - mx + 1 << "\n";
    }
    //int cnt2 = mx - mn + 1;
    else{
         cout << ans << " " << m - (mx - mn + 1) << "\n";
    } //cout << mx << " " << mn << "\n";
}

int main(){
    freopen("detect.in" , "r" , stdin);
    freopen("detect.out" , "w" , stdout);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
